package com.adopapa.ethexplorer.contoller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import reactor.core.publisher.Mono;

@RestControllerAdvice
@RequestMapping("/debugrecord/auth")
public class AuthController extends BaseController {

	@ExceptionHandler
	@RequestMapping(path = "/error", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> exception(Exception e) {
		logger.error(ExceptionUtils.getStackTrace(e));
		return Mono.just(error(e));
	}

	@RequestMapping(path = "/noauth", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> noauth(Exception e) {
		logger.error(ExceptionUtils.getStackTrace(e));
		Map<String, Object> response = new HashMap<String, Object>();
		response.put("code", "06");
		response.put("message", "No Permissions!");

		return Mono.just(response);
	}

	@RequestMapping(path = "/ok", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> ko() {
		return Mono.just(ok());
	}

}
